package com.gitee.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName GateWayConfig
 * @Description   gateway  路由配置的方式又两种
 *              1. 一种是直接在yml配置路由规则
 *              2. 一种是是使用编码的方式配置路由规则
 * @Author xiongchao
 * @Date 2020/12/21 14:31
 **/
@Configuration
public class GateWayConfig {

    @Bean
    public RouteLocator locator (RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        routes.route("baidu",
                r -> r.path("/baidu").uri("http://www.baidu.com")).build();
        return routes.build();
    }

    @Bean
    public RouteLocator locator1 (RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        routes.route("googl1e" ,
                r -> r.path("/gg").uri("http://www.google.cn")).build();
        return routes.build();
    }
}
